home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kolekce / d6 / rxlibsetup.exe / {app} / units / RxBDEReg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-02-19  |  8.8 KB  |  334 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 2001,2002 SGB Software          }
  6. {         Copyright (c) 1997, 1998 Fedor Koshevnikov,   }
  7. {                        Igor Pavluk and Serge Korolev  }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit RxBDEReg;
  12.  
  13. {$I RX.INC}
  14. {$D-,L-,S-}
  15.  
  16. interface
  17.  
  18. uses Classes, RTLConsts, DesignIntf, DesignEditors, VCLEditors, SysUtils, DB, DBTables;
  19.  
  20. { Register data aware custom controls }
  21.  
  22. procedure Register;
  23.  
  24. implementation
  25.  
  26. {$IFDEF WIN32}
  27.  {$R *.D32}
  28. {$ELSE}
  29.  {$R *.D16}
  30. {$ENDIF}
  31.  
  32. uses TypInfo, DBLists, RXLConst, DBQBE, DBFilter, DBIndex, DBPrgrss, 
  33.   RxLogin, DBSecur, RXQuery, VCLUtils, DbExcpt, RxDsgn,
  34.   {$IFDEF DCS} SelDSFrm, {$ENDIF} {$IFDEF RX_MIDAS} RxRemLog, {$ENDIF}
  35.   {$IFDEF RX_D3} QBndDlg, {$ELSE} 
  36.   {$IFNDEF WIN32} QBndDlg, {$ELSE} QBindDlg, {$ENDIF} {$ENDIF}
  37.   Consts, LibHelp, MemTable;
  38.  
  39. {$IFDEF WIN32}
  40.  
  41. { TSessionNameProperty }
  42.  
  43. type
  44.   TSessionNameProperty = class(TRxDBStringProperty)
  45.   public
  46.     procedure GetValueList(List: TStrings); override;
  47.   end;
  48.  
  49. procedure TSessionNameProperty.GetValueList(List: TStrings);
  50. begin
  51.   Sessions.GetSessionNames(List);
  52. end;
  53.  
  54. {$ENDIF WIN32}
  55.  
  56. { TDatabaseNameProperty }
  57.  
  58. type
  59.   TDatabaseNameProperty = class(TRxDBStringProperty)
  60.   public
  61.     procedure GetValueList(List: TStrings); override;
  62.   end;
  63.  
  64. procedure TDatabaseNameProperty.GetValueList(List: TStrings);
  65. {$IFDEF WIN32}
  66. var
  67.   S: TSession;
  68. {$ENDIF}
  69. begin
  70. {$IFDEF WIN32}
  71.   if (GetComponent(0) is TDBDataSet) then
  72.     (GetComponent(0) as TDBDataSet).DBSession.GetDatabaseNames(List)
  73.   else if (GetComponent(0) is TSQLScript) then begin
  74.     S := Sessions.FindSession((GetComponent(0) as TSQLScript).SessionName);
  75.     if S = nil then S := Session;
  76.     S.GetDatabaseNames(List);
  77.   end;
  78. {$ELSE}
  79.   Session.GetDatabaseNames(List);
  80. {$ENDIF}
  81. end;
  82.  
  83. { TTableNameProperty }
  84. { For TFieldList, TIndexList components }
  85.  
  86. type
  87.   TTableNameProperty = class(TRxDBStringProperty)
  88.   public
  89.     procedure GetValueList(List: TStrings); override;
  90.   end;
  91.  
  92. procedure TTableNameProperty.GetValueList(List: TStrings);
  93. begin
  94. {$IFDEF WIN32}
  95.   (GetComponent(0) as TCustomTableItems).DBSession.GetTableNames((GetComponent(0)
  96.     as TCustomTableItems).DatabaseName, '', True, False, List);
  97. {$ELSE}
  98.   Session.GetTableNames((GetComponent(0) as TCustomTableItems).DatabaseName,
  99.     '', True, False, List);
  100. {$ENDIF WIN32}
  101. end;
  102.  
  103. {$IFNDEF RX_D4}
  104.  
  105. {$IFNDEF VER90}
  106.  {$IFNDEF VER93}
  107. function EditQueryParams(DataSet: TDataSet; List: TParams): Boolean;
  108. begin
  109.   Result := QBndDlg.EditQueryParams(DataSet, List, hcDQuery);
  110. end;
  111.  {$ENDIF}
  112. {$ENDIF}
  113.  
  114. { TRxParamsProperty }
  115.  
  116. type
  117.   TRxParamsProperty = class(TPropertyEditor)
  118.   public
  119.     procedure Edit; override;
  120.     function GetValue: string; override;
  121.     function GetAttributes: TPropertyAttributes; override;
  122.   end;
  123.  
  124. function TRxParamsProperty.GetValue: string;
  125. var
  126.   Params: TParams;
  127. begin
  128.   Params := TParams(Pointer(GetOrdValue));
  129.   if Params.Count > 0 then
  130. {$IFDEF WIN32}
  131.     Result := Format('(%s)', [GetPropInfo.Name])
  132. {$ELSE}
  133.     Result := Format('(%s)', [GetPropInfo^.Name])
  134. {$ENDIF}
  135.   else
  136.     Result := ResStr(srNone);
  137. end;
  138.  
  139. function TRxParamsProperty.GetAttributes: TPropertyAttributes;
  140. begin
  141.   Result := [paMultiSelect, paDialog];
  142. end;
  143.  
  144. procedure TRxParamsProperty.Edit;
  145. var
  146.   List, Params: TParams;
  147.   Query: TDataSet;
  148.   QueryCreated: Boolean;
  149.   I: Integer;
  150. begin
  151.   QueryCreated := False;
  152.   if GetComponent(0) is TDataSet then
  153.     Query := GetComponent(0) as TDataSet
  154.   else begin
  155.     Query := TQuery.Create(GetComponent(0) as TComponent);
  156.     QueryCreated := True;
  157.   end;
  158.   try
  159.     Params := TParams(GetOrdProp(GetComponent(0), GetPropInfo));
  160.     if QueryCreated then TQuery(Query).Params := Params;
  161.     List := TParams.Create;
  162.     try
  163.       List.Assign(Params);
  164.       if EditQueryParams(Query, List) {$IFDEF WIN32} and not
  165.         List.IsEqual(Params) {$ENDIF} then
  166.       begin
  167. {$IFDEF WIN32}
  168.         Modified;
  169. {$ELSE}
  170.         if Designer <> nil then Designer.Modified;
  171. {$ENDIF}
  172.         Query.Close;
  173.         for I := 0 to PropCount - 1 do begin
  174.           Params := TParams(GetOrdProp(GetComponent(I),
  175.             TypInfo.GetPropInfo(GetComponent(I).ClassInfo,
  176. {$IFDEF WIN32}
  177.             GetPropInfo.Name)));
  178. {$ELSE}
  179.             GetPropInfo^.Name)));
  180. {$ENDIF}
  181.           Params.AssignValues(List);
  182.         end;
  183.       end;
  184.     finally
  185.       List.Free;
  186.     end;
  187.   finally
  188.     if QueryCreated then Query.Free;
  189.   end;
  190. end;
  191.  
  192. {$ENDIF RX_D4}
  193.  
  194. { TUserTableNameProperty }
  195. { For TDBSecurity component }
  196.  
  197. type
  198.   TUserTableNameProperty = class(TRxDBStringProperty)
  199.     procedure GetValueList(List: TStrings); override;
  200.   end;
  201.  
  202. procedure TUserTableNameProperty.GetValueList(List: TStrings);
  203. var
  204.   Security: TDBSecurity;
  205. begin
  206.   Security := GetComponent(0) as TDBSecurity;
  207.   if Security.Database <> nil then begin
  208. {$IFDEF WIN32}
  209.     Security.Database.Session.GetTableNames(Security.Database.DatabaseName,
  210.       '*.*', True, False, List);
  211. {$ELSE}
  212.     Session.GetTableNames(Security.Database.DatabaseName, '*.*',
  213.       True, False, List);
  214. {$ENDIF}
  215.   end;
  216. end;
  217.  
  218. { TLoginNameFieldProperty }
  219. { For TDBSecurity component }
  220.  
  221. type
  222.   TLoginNameFieldProperty = class(TRxDBStringProperty)
  223.     procedure GetValueList(List: TStrings); override;
  224.   end;
  225.  
  226. procedure TLoginNameFieldProperty.GetValueList(List: TStrings);
  227. var
  228.   Security: TDBSecurity;
  229.   Table: TTable;
  230. begin
  231.   Security := GetComponent(0) as TDBSecurity;
  232.   if (Security.Database <> nil) and (Security.UsersTableName <> '') then begin
  233.     Table := TTable.Create(Security);
  234.     try
  235.       Table.DatabaseName := Security.Database.DatabaseName;
  236.       Table.TableName := Security.UsersTableName;
  237.       Table.GetFieldNames(List);
  238.     finally
  239.       Table.Free;
  240.     end;
  241.   end;
  242. end;
  243.  
  244. {$IFDEF DCS}
  245.  
  246. { TMemoryTableEditor }
  247.  
  248. type
  249.   TMemoryTableEditor = class(TMemDataSetEditor)
  250.   protected
  251.     function CopyStructure(Source, Dest: TDataSet): Boolean; override;
  252.   end;
  253.  
  254. function TMemoryTableEditor.CopyStructure(Source, Dest: TDataSet): Boolean;
  255. begin
  256.   Result := Dest is TMemoryTable;
  257.   if Result then
  258.     TMemoryTable(Dest).CopyStructure(Source);
  259. end;
  260.  
  261. {$ENDIF DCS}
  262.  
  263. { Designer registration }
  264.  
  265. procedure Register;
  266. begin
  267. {$IFDEF RX_D4}
  268.   { Database Components are excluded from the STD SKU }
  269.   if GDAL = LongWord(-16) then Exit;
  270. {$ENDIF}
  271.  
  272. { Data aware components and controls }
  273.   RegisterComponents(LoadStr(srRXDBAware), [TRxQuery, TSQLScript,
  274.     TMemoryTable, TQBEQuery, TRxDBFilter, TDBIndexCombo, TDBProgress, 
  275.     TDBSecurity]);
  276. {$IFDEF RX_MIDAS}
  277. { MIDAS components }
  278.   RegisterComponents(LoadStr(srRXDBAware), [TRxRemoteLogin]);
  279.   RegisterNonActiveX([TRxRemoteLogin], axrComponentOnly);
  280. {$ENDIF}
  281. { Database lists }
  282.   RegisterComponents(LoadStr(srRXDBAware), [TBDEItems, TDatabaseItems,
  283.     TTableItems]);
  284. {$IFNDEF CBUILDER}
  285.  {$IFDEF USE_OLD_DBLISTS}
  286.   RegisterComponents(LoadStr(srRXDBAware), [TDatabaseList, TLangDrivList,
  287.     TTableList, TStoredProcList, TFieldList, TIndexList]);
  288.  {$ENDIF USE_OLD_DBLISTS}
  289. {$ENDIF CBUILDER}
  290.  
  291. {$IFDEF RX_D3}
  292.   RegisterNonActiveX([TRxQuery, TSQLScript, TMemoryTable, TQBEQuery,
  293.     TRxDBFilter, TDBIndexCombo, TDBProgress, TDBSecurity, TBDEItems,
  294.     TDatabaseItems, TTableItems], axrComponentOnly);
  295. {$ENDIF RX_D3}
  296.  
  297. { Property and component editors for data aware controls }
  298.  
  299.   RegisterPropertyEditor(TypeInfo(TFileName), TCustomTableItems, 'TableName',
  300.     TTableNameProperty);
  301.   RegisterPropertyEditor(TypeInfo(TFileName), TDBSecurity,
  302.     'UsersTableName', TUserTableNameProperty);
  303.   RegisterPropertyEditor(TypeInfo(string), TDBSecurity,
  304.     'LoginNameField', TLoginNameFieldProperty);
  305.  
  306. {$IFDEF DCS}
  307.   RegisterComponentEditor(TMemoryTable, TMemoryTableEditor);
  308. {$ENDIF}
  309.  
  310. {$IFNDEF RX_D4}
  311.   RegisterPropertyEditor(TypeInfo(TParams), TQBEQuery, 'Params',
  312.     TRxParamsProperty);
  313.   RegisterPropertyEditor(TypeInfo(TParams), TRxQuery, 'Macros',
  314.     TRxParamsProperty);
  315.   RegisterPropertyEditor(TypeInfo(TParams), TSQLScript, 'Params',
  316.     TRxParamsProperty);
  317. {$ENDIF}
  318.  
  319.   RegisterPropertyEditor(TypeInfo(string), TSQLScript, 'DatabaseName',
  320.     TDatabaseNameProperty);
  321. {$IFDEF WIN32}
  322.   RegisterPropertyEditor(TypeInfo(string), TCustomBDEItems, 'SessionName',
  323.     TSessionNameProperty);
  324.   RegisterPropertyEditor(TypeInfo(string), TSQLScript, 'SessionName',
  325.     TSessionNameProperty);
  326.   RegisterPropertyEditor(TypeInfo(string), TDBProgress, 'SessionName',
  327.     TSessionNameProperty);
  328. {$ELSE}
  329.   DbErrorIntercept;
  330. {$ENDIF WIN32}
  331.  
  332. end;
  333.  
  334. end.